//
//  StatusOriginalView.swift
//  微博项目
//
//  Created by zhaoyinpeng on 16/3/15.
//  Copyright © 2016年 zhaoyinpeng. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage

//.定义一个全局的间距
let StatusCellMargin: CGFloat = 10

class StatusOriginalView: UIView {

    var status: Status? {
        didSet {
            
            iconView.sd_setImageWithURL(status?.user?.headImageURL)
            nameLabel.text = status?.user?.name
            mbrank_image.image = status?.user?.mbrank_image
            verified_image.image = status?.user?.verified_type_image
            
            //.TODO: 后期完善
//            sourceLabel.text = status?.source
//            timeLabel.text = status?.text
            
            contentLabel.text = status?.text
            
            //.给配图视图设置数据源
            pictureView.imageURLs = status?.imageURLs
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //.MARK: 设置UI
    private func setupUI() {
        backgroundColor = UIColor.whiteColor()
        sepView.backgroundColor = UIColor(white: 0.99, alpha: 1)
        //.添加子控件
        addSubview(sepView)
        addSubview(iconView)
        addSubview(mbrank_image)
        addSubview(verified_image)
        addSubview(verified_image)
        addSubview(nameLabel)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(contentLabel)
        
        addSubview(pictureView)
        
    //.布局子控件
        sepView.snp_makeConstraints { (make) -> Void in
            make.top.left.right.equalTo(self)
            make.height.equalTo(StatusCellMargin)
        }
        
      iconView.snp_makeConstraints { (make) -> Void in
        make.left.equalTo(self.snp_left).offset(StatusCellMargin)
        make.top.equalTo(sepView.snp_bottom).offset(StatusCellMargin)
        make.size.equalTo(CGSizeMake(35, 35))
        }
        
       nameLabel.snp_makeConstraints { (make) -> Void in
        make.top.equalTo(iconView.snp_top)
        make.left.equalTo(iconView.snp_right).offset(StatusCellMargin)
        
        }
        
        mbrank_image.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(nameLabel.snp_top)
            make.left.equalTo(nameLabel.snp_right).offset(StatusCellMargin)
        }
        
        verified_image.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(iconView.snp_right)
            make.bottom.equalTo(iconView.snp_bottom)
        }
        
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(iconView.snp_bottom)
            make.left.equalTo(iconView.snp_right).offset(StatusCellMargin)
        }
        
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(timeLabel.snp_top)
            make.left.equalTo(timeLabel.snp_right).offset(StatusCellMargin)
        }
        
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconView.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(iconView.snp_left)
            make.right.equalTo(self.snp_right).offset(-StatusCellMargin)
        }
        
        
        pictureView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(contentLabel.snp_left)
            make.top.equalTo(contentLabel.snp_bottom).offset(StatusCellMargin)
            //.测试大小
//            make.size.equalTo(CGSizeMake(100, 100))
        }
        
        //将头像处理成圆形
        iconView.layer.cornerRadius = 18
        iconView.layer.masksToBounds = true
        
        //.添加原创微博底部的约束
        self.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin)
        }

    }
    
    //.懒加载视图
    private lazy var sepView: UIView = UIView()
    
    private lazy var iconView: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    private lazy var mbrank_image: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership"))
    private lazy var verified_image: UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
   
    private lazy var nameLabel: UILabel = UIFactory.labelFactory(UIColor.darkGrayColor(), fontSize: 16, text: "啦啦啦哈哈哈")
    
    private lazy var timeLabel: UILabel = UIFactory.labelFactory(UIColor.darkGrayColor(), fontSize: 11, text: "12:30")
    private lazy var sourceLabel: UILabel = UIFactory.labelFactory(UIColor.darkGrayColor(), fontSize: 10, text: "iphone10")
    private lazy var contentLabel: UILabel = UIFactory.labelFactory(UIColor.darkGrayColor(), fontSize: 13, text: "成功没有捷径！", alignment: .Left)
    
    //.配图视图
    private lazy var pictureView:StatusPictureView = StatusPictureView()
    
}
